﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;

namespace UseZXing
{
    public class BarCode : LuminanceSource
    {


        public static string imagePath = "C:\\Img\\2.jpg";

        public override byte[] Matrix
        {
            get
            {
                Bitmap bitmap = new Bitmap(imagePath);
                return BitmapToByteArray(bitmap);
            }
        }


        public BarCode(int width, int height) : base(width, height)
        {
        }



        public override byte[] getRow(int y, byte[] row)
        {
            throw new NotImplementedException();
        }


        static byte[] BitmapToByteArray(Bitmap bitmap)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                // 将图像保存到 MemoryStream 中
                bitmap.Save(stream, ImageFormat.Jpeg); // 根据实际图像格式进行选择

                // 将 MemoryStream 中的数据转为 byte[]
                return stream.ToArray();
            }
        }
    }
}
